<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${ctx }/style/css_member.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx }/js/common.js"></script>
<script type="text/javascript" src="${ctx }/js/jquery-1.3.2.js"></script>
<script type="text/javascript" src="${ctx }/js/ajaxupload.js"></script>
<title>添加文章</title>

<script type="text/javascript">

$(document).ready(function(){

	new AjaxUpload("#uploadFile", {
		action : "${ctx }/fileUpload!uploadBackgroundImage.do",
		autoSubmit : true,
		name : "myFile",
		onSubmit : function(file, extension) {
			if (extension && /^(jpg|png|jpeg|gif)$/i.test(extension)) {
			} else {
				alert("你所选择的文件不受系统支持");
				return false;
			}
		},
		onComplete : function(file, response) {
			var img = document.createElement("img");
    	    img.style.width =  "200px";
    		img.style.height = "250px";
    		$("#picImage").val(response);
    		img.src = '${img_server}/UploadImages/'+response+'?tempid='+new Date().getTime();
    		switch_image(img);
		}
	});

	m2('m1_007','m1_007_03');
});

function clearAllNode(parentNode){
    while (parentNode.firstChild) {
      var oldNode = parentNode.removeChild(parentNode.firstChild);
       oldNode = null;
     }
}

function switch_image(img)
{
	clearAllNode(document.getElementById("photoTd"));
	document.getElementById("photoTd").appendChild(img);
}

function checkForm(){

	var title = $.trim($("#title").val());
	if (title == "") {
		$("#title").focus();
		alert("请填写文章标题。");
		return false;
	}

	var htmlContent = $("#htmlContent").val();
	if (htmlContent == "") {
		alert("请填写文章的文案。");
		return false;
	}

	$("#articleForm").submit();
}

function gobackToArticleList(){

	location.href = "${ctx}/article/articleAction!list.do";
}

</script>
</head>


<body>

<!-- 页面头部  -->
<jsp:include page="/commons/head_member.jsp"></jsp:include>

<form action="${ctx}/article/articleAction!save.do" method="post" id="articleForm" name="articleForm" enctype="multipart/form-data">
	<table width="960" cellspacing="0" cellpadding="0" align="center" class="tbl_add_border">
              <tr>
                <td colspan="100%" class="bt14A" align="center">发布文章</td>
              </tr>
              <tr>
                <td valign="top" class="bt14A" align="right"><span class="style15">*</span> 文章标题：</td>
                <td valign="top" class="bt14A"><input name="article.title" type="text" size="40" id="title"></td>
                <td width="215" rowspan="5" valign="top">
                  <table width="200" height="250" border="0" cellpadding="0" cellspacing="1" bordercolor="#CCCCCC" bgcolor="#CCCCCC">
                    <tr>
                      <td bgcolor="#FFFFFF" id="photoTd">&nbsp;</td>
                    </tr>
                  </table>
                 </td>
              </tr>
              <tr>
                <td valign="top" class="bt14A" align="right"><span class="style15">*</span> 文章来源：</td>
                <td valign="top" class="bt14A"><input name="article.original" type="text" size="25" id="original"></td>
              </tr>
              <tr>
                <td valign="top" class="bt14A" align="right">图片：</td>
                <td valign="top" class="bt14A"><span id="uploadFile" style="color: #0000FF">上传</span></td>
              </tr>
              <tr>
                <td valign="top" class="bt14A" align="right"><span class="style15">*</span> 文案：</td>
                <td valign="top" class="bt14A">
                 	 <textarea name="article.htmlContent" cols="70" rows="30" id="htmlContent"></textarea>
				</td>
              </tr>
              <tr>
                <td width="128" valign="top" class="nw12a">
                        <!-- 隐藏域 begin -->
				        	<input type="hidden" name="picImage" id="picImage"/>
				        <!-- 隐藏域 end -->
                </td>
                <td width="575" valign="top" class="nw12a">
                	<input type="button" value="保存" style="cursor: pointer ;"  onclick="checkForm()">
                	<input type="button" value="返回文章列表" style="cursor: pointer ;"  onclick="gobackToArticleList()">
                </td>
              </tr>
              <tr><td colspan="100%" height="20"></td></tr>
  </table>
</form>

<jsp:include page="/commons/foot_member.jsp"></jsp:include>

</body>
</html>